//
//  FKCollectFilterCell.m
//  GC_OC
//
//  Created by Macbook Pro on 2023/5/13.
//

#import "FKCollectFilterCell.h"
#import "FKCategory.h"

@interface FKCollectFilterCell ()

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *badgeLabel;

@end

@implementation FKCollectFilterCell

- (void)setupSubviews
{
    [super setupSubviews];
    
    self.selectionStyle = UITableViewCellSelectionStyleDefault;
    
    UILabel *titleLabel = [UILabel fk_labelWithFont:fk_adjustFont(16) textColor:fkColor333333];
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UILabel *badgeLabel = [UILabel fk_labelWithFont:fk_adjustFont(8) textColor:UIColor.whiteColor textAlignment:NSTextAlignmentCenter];
    [self.contentView addSubview:badgeLabel];
    self.badgeLabel = badgeLabel;
    badgeLabel.backgroundColor = [UIColor fk_colorWithHex:0xfa6400];
    [badgeLabel fk_viewCornerRadius:fk_adjustW(7) borderWidth:0 borderColor:nil];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.bottom.offset(0);
        make.right.mas_lessThanOrEqualTo(fk_adjustW(-18));
    }];
    [badgeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(fk_adjustW(14));
        make.left.equalTo(titleLabel.mas_right);
        make.top.offset(fk_adjustW(4));
    }];
}

- (void)setupSelectedState
{
    if (self.isSelected) {
        self.titleLabel.textColor = fkMainColor;
    } else {
        self.titleLabel.textColor = fkColor333333;
    }
    self.badgeLabel.backgroundColor = [UIColor fk_colorWithHex:0xfa6400];
}

- (void)setData:(id)data
{
    [super setData:data];
    
    if ([data isKindOfClass:[FKCategory class]]) {
        FKCategory *model = data;
        
        self.titleLabel.text = model.name;
        self.titleLabel.font = model.id.length > 0 ? fk_adjustFont(14) : fk_adjustBoldFont(14);
        if (model.id.length > 0 && model.children.count > 0) {
            self.badgeLabel.text = fkFORMAT(@"%zd", model.children.count);
            self.badgeLabel.hidden = false;
        } else {
            self.badgeLabel.hidden = true;
        }
    }
}

@end
